import EventEmitter from 'events'
import WSProxyClient from '../WSProxyClient'
import BarrageClient from '../BarrageClient'

export default class WholeClient extends EventEmitter {
  constructor (room) {
    super()
    this.room = room
    this.clientWSProxy = new WSProxyClient(room)
    this.clientBarrage = new BarrageClient(room)

    this.clientWSProxy.on('pack', this._onPack.bind(this))
    this.clientBarrage.on('pack', this._onPack.bind(this))
  }

  connect () {
    this.clientWSProxy.connect()
    this.clientBarrage.connect()
    // 理论上应该让clientBarrage基于clientWSProxy创建, 可考虑优化
  }

  close () {
    this.clientWSProxy.close()
    this.clientBarrage.close()
  }

  _onPack (pack) {
    this.emit('pack', pack)
  }
}
